home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / util / misc / Fudgit233.lha / Source / src / readline / keymaps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-14  |  3.7 KB  |  163 lines

  1. /* keymaps.c -- Functions and keymaps for the GNU Readline library. */
  2.  
  3. /* Copyright (C) 1988,1989 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Readline, a library for reading lines
  6.    of text with interactive input and history editing.
  7.  
  8.    Readline is free software; you can redistribute it and/or modify it
  9.    under the terms of the GNU General Public License as published by the
  10.    Free Software Foundation; either version 1, or (at your option) any
  11.    later version.
  12.  
  13.    Readline is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with Readline; see the file COPYING.  If not, write to the Free
  20.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. #include "keymaps.h"
  23. #include "emacs_keymap.c"
  24.  
  25. #ifdef VI_MODE
  26. #include "vi_keymap.c"
  27. #endif
  28.  
  29. /* Remove these declarations when we have a complete libgnu.a. */
  30. #define STATIC_MALLOC
  31. #ifndef STATIC_MALLOC
  32. extern char *xmalloc ();
  33. #else
  34. static char *xmalloc (int bytes);
  35. #endif
  36.  
  37. /* **************************************************************** */
  38. /*                                    */
  39. /*              Functions for manipulating Keymaps.        */
  40. /*                                    */
  41. /* **************************************************************** */
  42.  
  43.  
  44. /* Return a new, empty keymap.
  45.    Free it with free() when you are done. */
  46.  
  47. extern void free (void *);
  48. extern void *malloc (unsigned);
  49. extern void *realloc (void *, unsigned);
  50. extern void abort(void);
  51.  
  52. Keymap
  53. rl_make_bare_keymap (void)
  54. {
  55.   register int i;
  56.   Keymap keymap = (Keymap)xmalloc (128 * sizeof (KEYMAP_ENTRY));
  57.  
  58.   for (i = 0; i < 128; i++)
  59.     {
  60.       keymap[i].type = ISFUNC;
  61.       keymap[i].function = (KFunction *)NULL;
  62.     }
  63.  
  64.   for (i = 'A'; i < ('Z' + 1); i++)
  65.     {
  66.       keymap[i].type = ISFUNC;
  67.       keymap[i].function = rl_do_lowercase_version;
  68.     }
  69.  
  70.   return (keymap);
  71. }
  72.  
  73. /* Return a new keymap which is a copy of MAP. */
  74. Keymap
  75. rl_copy_keymap (Keymap map)
  76. {
  77.   register int i;
  78.   Keymap temp = rl_make_bare_keymap ();
  79.  
  80.   for (i = 0; i < 128; i++)
  81.     {
  82.       temp[i].type = map[i].type;
  83.       temp[i].function = map[i].function;
  84.     }
  85.   return (temp);
  86. }
  87.  
  88. /* Return a new keymap with the printing characters bound to rl_insert,
  89.    the uppercase Meta characters bound to run their lowercase equivalents,
  90.    and the Meta digits bound to produce numeric arguments. */
  91. Keymap
  92. rl_make_keymap (void)
  93. {
  94.   register int i;
  95.   Keymap newmap;
  96.  
  97.   newmap = rl_make_bare_keymap ();
  98.  
  99.   /* All printing characters are self-inserting. */
  100.   for (i = ' '; i < 126; i++)
  101.     newmap[i].function = rl_insert;
  102.  
  103.   newmap[TAB].function = rl_insert;
  104.   newmap[RUBOUT].function = rl_rubout;
  105.   newmap[CTRL('H')].function = rl_rubout;
  106.  
  107.   return (newmap);
  108. }
  109.  
  110. /* Free the storage associated with MAP. */
  111. void rl_discard_keymap (Keymap map)
  112. {
  113.   int i;
  114.  
  115.   if (!map)
  116.     return;
  117.  
  118.   for (i = 0; i < 128; i++)
  119.     {
  120.       switch (map[i].type)
  121.     {
  122.     case ISFUNC:
  123.       break;
  124.  
  125.     case ISKMAP:
  126.       rl_discard_keymap ((Keymap)map[i].function);
  127.       break;
  128.  
  129.     case ISMACR:
  130.       free ((char *)map[i].function);
  131.       break;
  132.     }
  133.     }
  134. }
  135.  
  136. #ifdef STATIC_MALLOC
  137.  
  138. /* **************************************************************** */
  139. /*                                    */
  140. /*            xmalloc and xrealloc ()                     */
  141. /*                                    */
  142. /* **************************************************************** */
  143.  
  144. static void memory_error_and_abort (void);
  145.  
  146. static char *
  147. xmalloc (int bytes)
  148. {
  149.   char *temp = (char *)malloc (bytes);
  150.  
  151.   if (!temp)
  152.     memory_error_and_abort ();
  153.   return (temp);
  154. }
  155.  
  156. static void
  157. memory_error_and_abort (void)
  158. {
  159.   fprintf (stderr, "readline: Out of virtual memory!\n");
  160.   abort ();
  161. }
  162. #endif /* STATIC_MALLOC */
  163.